﻿using System.Data;
using System.Data.SqlClient;
using System;

namespace Adams.Web.Areas.MyAdams.Data.Profile
{
    public static class Index
    {
        public static Adams.Web.Areas.MyAdams.Models.Profile.Index.PageLoad PageLoad(int memberId)
        {
            var data = new Adams.Web.Areas.MyAdams.Models.Profile.Index.PageLoad();

            using (SqlDataReader dr = Adams.Web.Data.DB.RunDataReader(@"
SELECT M.*
FROM Membership.Members M
WHERE M.MemberID = @MemberID
", CommandType.Text,
    Adams.Web.Data.DB.CreateParameter("@MemberID", memberId)))
            {
                if (dr.HasRows)
                {
                    dr.Read();
                    data.Member = Adams.Web.Data.DB.InitFromReader<Adams.Shared.Entities.Membership.Member>(dr, new Adams.Web.Data.ColMap { NameInDb = "MemberID", NameInObject = "ID" });
                }
            }

            return data;
        }
    }
}
